package org.ihelpuoo.lang;

import java.io.PrintWriter;

import org.ihelpuoo.io.StringBufferOutputStream;

public class ExceptionUtils
{
	public static String dump(Throwable e)
	{
		if (null == e)
			return null;
		StringBuffer sb = new StringBuffer();
		PrintWriter pw = new PrintWriter(new StringBufferOutputStream(sb));
		e.printStackTrace(pw);
		pw.flush();
		return sb.toString();
	}

	public static String dumpBrief(Throwable e)
	{
		if (null == e)
			return null;
		return (new StringBuffer("!!!").append(e.getClass().getSimpleName())).append(':').append(
				e.getMessage()).toString();
	}

	public static RuntimeException castToRuntimeException(Throwable e)
	{
		if (e instanceof RuntimeException)
			return (RuntimeException)e;
		else
			return new RuntimeException(e);
	}
}
